//当前数字，跟之后的所有数字比较,差值大于最大值，则重新赋值最大值
function forcefind(nums:number[]):number{
  let ret = 0
  for (let i = 0; i < nums.length; i++) {
    const pre = nums[i];
    for (let j = i+1 ; j < nums.length; j++) {
      const after = nums[j];
      if((after - pre) > ret) {
        ret = after - pre
      }
      
    }
  }
  return ret
}

//只遍历一遍-思路：当前-最小值 > 已经记录的最大值
function find_o1(nums:number[]):number{
  let min = Number.MAX_VALUE
  let benifit = 0
  for (let i = 0; i < nums.length; i++) {
    if(nums[i] - min > benifit) {
      benifit  = nums[i] - min
    }
    if(nums[i] < min) {
      min = nums[i]
    }
  }
  return benifit
}
console.log(find_o1([7,1,5,3,6,4]))